#include "../sour/TcpServer.hpp"
void OnClosed(const PtrConnection& conn)//连接关闭 
{
    DEBUG_LOG("CLOSE CONNECTION:%p", conn.get());
}
void OnConnected(const PtrConnection& conn)//新连接建立成功
{
    DEBUG_LOG("NEW CONNECTION:%p", conn.get());
}
void OnMessage(const PtrConnection& conn, Buffer* buffer)//消息来了 
{
    DEBUG_LOG("%s", buffer->ReadPosition());
    buffer->MoveReadOffset(buffer->ReadAbleSize());//将读偏移向后移动
    std::string str = "Hello world";
    conn->Send(str.c_str(), str.size());//发送数据，将数据放到发送缓冲区，启动写事件监控
    //conn->Shutdown(); //提供给组件使用者的关闭接口,并不是立即关闭（先判断有没有数据待处理）
}
int main()
{
    TcpServer server(8500);
    server.SetThreadCount(2);
    server.EnableInactiveReleanse(10);
    server.SetClosedCallBack(OnClosed);
    server.SetConnectedCallBack(OnConnected);
    server.SetMessageCallBack(OnMessage);
    server.Start();
    return 0;
}